package org.opens.controller;

import org.opens.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 功能:
 *
 * @author zym
 * @Date 2022/6/28 17:04
 */
@RestController
@RequestMapping(value = "/api/redis")
public class RedisController {

    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    @RequestMapping(value = "/getValue")
    public R<String> getValue(@RequestParam(value = "key") String key) {
        String result = redisTemplate.opsForValue().get(key);
        return R.success(result);
    }

    @RequestMapping(value = "/setValue")
    public R<Boolean> setValue(@RequestParam(value = "key") String key, @RequestParam(value = "value") String value) {
        redisTemplate.opsForValue().set(key, value);
        return R.success(true);
    }

}
